;.pagewidth 98t ;Set Page Width (For P&E) ;********************************************************************* ;* Title: UserMonQT4.asm Copyright (c) Motorola 2002 ;* User Mode Monitor for MC68HC908QT/QY Series Jim Sib 7/20/02 ;* For additional information see Application note AN2305/D ;* ;* This code is programmed into the flash memory to allow entry into ;* monitor mode (Mon08) without any special levels or Vtst. ;* This will allow a very low cost target system to be programmed or ;* debugged directly from P&E or CodeWarrior through a simple serial ;* cable. ;* Like other ROM monitors, this code requires a pseudo-vector ;* mechanism to redirect vectors to locations in unprotected flash ;* below the area of this small code segment. ;********************************************************************* ; base 10t ;change default to decimal (For P&E) ;*** Equates for registers and routines in MC68HC908Qx *************** PTA: equ $0000 ;Port A register PTA0: equ 0 ;bit # for PTA0 PTA2: equ 2 ;bit # for PTA2/IRQ pin PTAPUE: equ $000B ;Port A pullup enable bits PTAPUE2: equ 2 ;bit # for PTA2 pullup enable CONFIG1: equ $001F ;CONFIG1 register COPD: equ 0 ;COPD in bit #0 mCOPD: equ %00000001 ;bit mask for COPD InitConfig1: equ %01001001 ;default initialization for monitor ; |||||||| CONFIG1 is a write-once register ; |||||||+-COPD - 1 disable COP watchdog ; ||||||+--STOP - 0 disable STOP instruction ; |||||+---SSREC - 0 4096 cycle STOP recovery ; ||||+----LVI5OR3 - 1 set LVI for 5v system ; |||+-----LVIPWRD - 0 enable power to LVI system ; ||+------LVIRSTD - 0 enable reset on LVI trip ; |+-------LVISTOP - 1 enable LVI in STOP mode ; +--------COPRS - 0 long COP timeout OSCTRIM: equ $0038 ;working ICG trim setting TRIMLOC: equ $FFC0 ;nonvolatile trim value (flash) FLBPR: equ $FFBE ;flash block protect reg (flash) IGetPut: equ $2D6B ;Mon08 GetPut routine for int osc IMonSwi: equ $2CF9 ;Mon08 SWI ISR for int osc UConfig1: equ $FDEA ;nonvolatile user value for CONFIG1 ;* Monitor checks this user supplied value and uses it if it has been ;* programmed with a CONFIG1 value that is compatible with the monitor ;* which requires COP to be disabled and LVI to be powered and enabled ;* If these conditions are not met, the monitor uses InitConfig1 value ;*** Equates to setup alternate vectors ****************************** ;* actual vectors will pass control to these locations. ;* user code would include jump instructions at these locations that ;* jump to the user's interrupt service routines, for example… ;* org AltADC ;* jmp ADCisr ;* jmp KBDisr ;* ;********************************************************************* AltADC: equ $FDEB ;Alternate ADC interrupt vector AltKBD: equ $FDEE ; ' KBD wakeup ' ' AltTOF: equ $FDF1 ; ' TOF ' ' AltTCH1: equ $FDF4 ; ' Timer Ch.1 ' ' AltTCH0: equ $FDF7 ; ' Timer Ch.0 ' ' AltIRQ: equ $FDFA ; ' IRQ ' ' AltRESET: equ $FDFD ; ' RESET ' ' org FLBPR ;flash block protect location fcb $FE ;protect this code, FLBPR,& vectors org $FFB0 ;start of upper 96 bytes of flash UMonReset: lda TRIMLOC ;get nonvolatile trim value sta OSCTRIM ;set working trim value in ICG bclr PTA0,PTA ;initialize PTA0 for serial comms bset PTAPUE2,PTAPUE ;enable int pullup on PTA2/IRQ pin lda AltRESET+1 ;MSB of user reset vector bra toFFC2 ;around FLBPR and trim values ;* FLBPR and oscillator trim value are located at $FFBE-FFC1 org $FFC2 ;immediately after nonvolatile trim toFFC2: inca ;test for $FF->$00 beq MonStart ;if reset vector blank, go MonStart brclr PTA2,PTA,MonStart ;If IRQ=0 @ reset, enter monitor jmp AltRESET ;IRQ high so start user program MonStart: lda UConfig1 ;get user's value for CONFIG1 tax ;save a copy and #%00110001 ;check for LVI on, COP reset off cmp #%00000001 ;LVIRSTD=LVIPWRD=0, COPD=1 beq skipload ;if so value in X is OK ldx #InitConfig1 ;else force default settings skipload: stx CONFIG1 ;write-once register to set config bra toFFE2 ;around ADC and KBD vectors ;* ADC and KBD vectors are located at $FFDE-FFE1 org $FFE2 ;unused block in vectors toFFE2: ldx #8 ;loop count for 8 characters LoopSec: jsr IGetPut ;get and echo a security character dbnzx LoopSec ;get and ignore 8 characters swi ;start Mon08 org $FFDE ;beginning of QY4/QT4 vectors VADC: fdb AltADC ;point to alternate vectors VKBD: fdb AltKBD ;* There is a gap from $FFE2-FFF1 that is used for user monitor code org $FFF2 ;skip unused vector locations VTOF: fdb AltTOF VTCH1: fdb AltTCH1 VTCH0: fdb AltTCH0 fdb $FFFF ;fill unused location with $FFFF VIRQ: fdb AltIRQ VSWI: fdb IMonSwi ;SWI service routine in Mon08 ROM VRESET: fdb UMonReset ;to start of user mode monitor